/* $Header: cc_cmds.c,v 2.3 02/07/26 12:31:35 przybyls Exp $ */


/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: cc_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*                                                                     */
/* MODULE PURPOSE: This module will handle the chem comm commands.     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

/*
 */

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include  <typedefs.h>
#include  <error.h>
#include  <p_wkfile.h>
#include  <wkfile.h>
#include  <ramps.h>
#include  <config.h>
#include  <zone_config.h>
#include  <zone_status.h>
#include  <status.h>
#include  <kbd_ui.h>
#include  <display.h>
#include  <run_ui.h>
#include  <exception.h>
#include  <err_handler.h>
#include  <diag.h>
#include  <clock_ui.h>

#include  <method.h>
#include  <cmd_tbls.h>


#include <i_op.h>
#include <sig_types.h>
#include <sigpath.h>
#include <sig_ui.h>

#include <mio.h>
#include <cmd_set.h>
#include <cmdproc.h>
#include <hostutil.h>
#include <wkfutil.h>
#include <seq_cmds.h>
#include <sequence.h>
#include <als.h>
#include <als_ui.h>
#include <seq_ui.h>

#include <glp.h>
#include <flash.h>

UI_ERR     CheckSequenceCheckArea(void);



/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/



/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

extern U_INT16 PF_Start;
extern U_INT16 MF_Start;

extern  QUEUE_TYPE  MIO_Rd_Free_Q;
extern  QUEUE_TYPE  MIO_Wr_Free_Q;
extern  QUEUE_TYPE  MIO_Wr_Output_Q;

extern  BIT8          *pIn_Msg;      /* ptr to next byte in msg for scanner */
extern  U_INT16        In_Msg_Len;   /* length of remaining message */

/* used by IO Description Request */
/*
extern  U_INT8   Mio_IO_Description_Response;
extern  U_INT8   Mio_Description_Info[];
*/

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

/* if BC_DEBUG is defined debug buffers are created and statics become global */
#define BC_DEBUG

/* when debugging make variables global for emulator testing */
#ifdef BC_DEBUG
#   define SCOPE
#else
#   define  SCOPE  static
#endif


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   MACROS                  */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/



/***********************************************************************/
/* FUNCTION: DoCCEO                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Echo command.                                              */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoCCEO(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
U_INT16 len;

   len = 0;

   if (p_cmd->parmv[0] == 1)
   {
      len = PutAsciiParam((BIT8 *)"\"", p_resp_parm);
      len += PutAsciiParam((BIT8 *)&(p_cmd->parms[p_cmd->parmv[1]]),
                                     p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)"\"", p_resp_parm+len);
      return len;
   }
   else
   {
      CmdErrorHandler(p_cmd,1,INVALID_PARAM);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoCCEO                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCC98                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: temp command                                               */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


INT16 DoCC98(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
/* Reverse the conditional compile to return no response */
/* Possibly reactivate a version of this command later */
#if 1
(void)p_cmd;
(void)p_resp_parm;
   /* function used for testing only */
   return NO_RESPONSE;
#else



INT16    len;
U_INT32  start_time;
U_INT8   time_out;
INT32    entry;
UI_ERR   error;

   len = 0;

   switch(p_cmd->parmv[0])
   {
   case 1:
      error = DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry);
      /* check for valid parameters */
      if( ((U_INT16)error != 0 ) || ((entry >= 0 ) && (entry <= 0xFF)) )
      {
         /* Get requested line of description text */
         Mio_IO_Description_Response = FALSE;
         MioIODescription((U_INT8) entry);
      }
      else
      {
         CmdErrorHandler(p_cmd,1,INVALID_PARAM);
         return NO_RESPONSE;
      }

      /* wait for response from command and return string */
      /* time out after atleast two seconds */
      start_time = Uptime_Clock;
      time_out = FALSE;
      while ( (Mio_IO_Description_Response == FALSE) &&
                            (time_out == FALSE) )
      {
         /* wait for response */
         if( (Uptime_Clock - start_time) > 2 )
         {
            time_out = TRUE;
         }
      }
      if( time_out == FALSE )
      {
         len = PutAsciiParam((BIT8 *)Mio_Description_Info,p_resp_parm);
      }
      else
      {
         len = PutAsciiParam((BIT8 *)"6890: MIO DESCRIPTION TIMEOUT",p_resp_parm);
      }
      return  len;
   default:
      CmdErrorHandler(p_cmd,2, INVALID_PARAM);
      return NO_RESPONSE;
   }
#endif
}

/***********************************************************************/
/* END FUNCTION: DoCC89                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCC99                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: temp command to test DecToInt and IntToDec.                */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


INT16 DoCC99(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
/* Reverse the conditional compile to return no response */
/* Possibly reactivate a version of this command later */
#if 1
(void)p_cmd;
(void)p_resp_parm;
   /* function used for testing only */
   return NO_RESPONSE;
#else

INT16    len;
U_INT32  start_time;
U_INT8   time_out;
   len = 0;

   switch(p_cmd->parmv[0])
   {
   case 1:
      switch( p_cmd->parms[p_cmd->parmv[1]] )
      {
      case '0':
      case 'I':
         /*
          * initialize MIO configuration state machine and get first
          *   configuration item along with the currently set parameter
          */
         Mio_Ascii_IO_Config_Response = FALSE;
         MioAsciiIOConfig(FIRST_ITEM);
         break;

      case '1':
      case 'M':
         /*
          * Get next configuration item along with that item's currently
          *   set parameter
          */
         Mio_Ascii_IO_Config_Response = FALSE;
         MioAsciiIOConfig(NEXT_ITEM);
         break;
      case '2':
         /*
          * Get previous configuration item along with that item's currently
          *   set parameter
          */
         Mio_Ascii_IO_Config_Response = FALSE;
         MioAsciiIOConfig(PREV_ITEM);
         break;
      case '3':
      case '^':
         /*
          * Get next configuration parameter
          */
         Mio_Ascii_IO_Config_Response = FALSE;
         MioAsciiIOConfig(NEXT_PARAM);
         break;
      case '4':
      case 'V':
         /*
          * Get previous configuration parameter
          */
         Mio_Ascii_IO_Config_Response = FALSE;
         MioAsciiIOConfig(PREV_PARAM);
         break;
      case '5':
      case 'E':
         /*
          * Set last returned parameter in active configuration item and
          *   return the active item and parameter
          */
         Mio_Ascii_IO_Config_Response = FALSE;
         MioAsciiIOConfig(SET_LAST_PARAM);
         break;
      default:
         CmdErrorHandler(p_cmd,1, INVALID_PARAM);
         return NO_RESPONSE;
      }

      /* wait for response from command and return string */
      /* time out after atleast two seconds */
      start_time = Uptime_Clock;
      time_out = FALSE;
      while ( (Mio_Ascii_IO_Config_Response == FALSE) &&
                            (time_out == FALSE) )
      {
         /* wait for response */
         if( (Uptime_Clock - start_time) > 2 )
         {
            time_out = TRUE;
         }
      }
      if( time_out == FALSE )
      {
         len = PutAsciiParam((BIT8 *)Mio_Display_Info,p_resp_parm);
      }
      else
      {
         len = PutAsciiParam((BIT8 *)"MIO CONFIG TIMEOUT",p_resp_parm);
      }
      return  len;
   default:
      CmdErrorHandler(p_cmd,2, INVALID_PARAM);
      return NO_RESPONSE;
   }
#endif
}

/***********************************************************************/
/* END FUNCTION: DoCC99                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCID                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCID command.                                */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoCCID(BIT8 *p_resp_parm)
{
INT16  len;

      len = 0;

      /* Instrument Model Number */
      len += PutAsciiParam((BIT8 *)"HP 6890 GC ",p_resp_parm+len);

      /* Firmware rev */
      len += PutAsciiParam((BIT8 *)" REV ",p_resp_parm+len);
      len += TransferVersion( p_resp_parm+len );

      return  len;

}

/***********************************************************************/
/* END FUNCTION: DoCCID                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCLA                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCLA command which gets/sets LAN addresses   */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCLA(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT16    len;
   INT8     i;
   BIT8     Bootp_Temp;
   UI_ERR   error;
   INT32    entry;
   U_INT16  pnum;
   IP_ADDRESS_TYPE IP_Temp;
   IP_ADDRESS_TYPE Gateway_Temp;
   IP_ADDRESS_TYPE Subnet_Temp;
   U_INT32  mask;

   len = 0;
   pnum = 1;

   if( (p_cmd->parmv[0] == 1) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {

      len += PutIntParam((INT32)LAN_bootp_mode, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      for (i=0; i<=3; i++)
      {
         len += PutIntParam((INT32)IP_Address.byte[i], p_resp_parm+len, 0);
         len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
      }

      for (i=0; i<=3; i++)
      {
         len += PutIntParam((INT32)Subnet.byte[i], p_resp_parm+len, 0);
         len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
      }

      for (i=0; i<=3; i++)
      {
         len += PutIntParam((INT32)Gateway.byte[i], p_resp_parm+len, 0);
         len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
      }

      p_resp_parm[--len] = 0;

      return len;
   }
   else
   {
      if ((p_cmd->parmv[0] > 0) && (p_cmd->parmv[0] <=13))
      {
         Bootp_Temp   = LAN_bootp_mode;
         IP_Temp      = IP_Address;
         Subnet_Temp  = Subnet;
         Gateway_Temp = Gateway;

         error = OK;

         if( (error == OK)          &&
             (p_cmd->parmv[0] >= 1) &&
             (p_cmd->parms[p_cmd->parmv[1]] != 0) )
         {
            error = DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry);
            if (error == OK)
            {
               if ((entry >= 0) && (entry <= 1)) Bootp_Temp = (BIT8)entry;
               else error = INVALID_PARAM;
            }
         }

         for (i=0; i<=3; i++)
         {
            if( (error == OK)          &&
                (p_cmd->parmv[0] >= 2+i) &&
                (p_cmd->parms[p_cmd->parmv[2+i]] != 0) )
            {
               pnum = 2+i;
               error = DecToInt(&p_cmd->parms[p_cmd->parmv[pnum]],0,&entry);
               if (error == OK)
               {
                  if ((entry >= 0) && (entry <= 255)) IP_Temp.byte[i] = (U_INT8)entry;
                  else error = INVALID_PARAM;
               }
            }
         }


         for (i=0; i<=3; i++)
         {
            if( (error == OK)          &&
                (p_cmd->parmv[0] >= 6+i) &&
                (p_cmd->parms[p_cmd->parmv[6+i]] != 0) )
            {
               pnum = 6+i;
               error = DecToInt(&p_cmd->parms[p_cmd->parmv[pnum]],0,&entry);
               if (error == OK)
               {
                  if ((entry >= 0) && (entry <= 255)) Subnet_Temp.byte[i] = (U_INT8)entry;
                  else error = INVALID_PARAM;
               }
            }
         }


         for (i=0; i<=3; i++)
         {
            if( (error == OK)          &&
                (p_cmd->parmv[0] >= 10+i) &&
                (p_cmd->parms[p_cmd->parmv[10+i]] != 0) )
            {
               pnum = 10+i;
               error = DecToInt(&p_cmd->parms[p_cmd->parmv[pnum]],0,&entry);
               if (error == OK)
               {
                  if ((entry >= 0) && (entry <= 255)) Gateway_Temp.byte[i] = (U_INT8)entry;
                  else error = INVALID_PARAM;
               }
            }
         }

         if (error == OK)
         {
            mask = Subnet_Temp.value;
            i = 0;
            while (mask != 0)
            {
               if ((mask & 0x80000000) == 0)
               {
                  error = INVALID_PARAM;
                  pnum = 5 + (i/8);
                  mask = 0;
               }
               else
               {
                  mask = mask << 1;
                  i = i + 1;
               }
            }
            if (i >= 32)
            {
               Subnet_Temp.value = 0;
            }
         }


         if (error != OK)
         {
            CmdErrorHandler(p_cmd, pnum, error);
         }
         else
         {
            LAN_bootp_mode = Bootp_Temp;
            IP_Address    = IP_Temp;
            Subnet        = Subnet_Temp;
            Gateway       = Gateway_Temp;
         }
      }
      else
      {
         CmdErrorHandler( p_cmd, 1, SYNTAX_ERROR );
      }

      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoCCLA                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCLS                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCLS command which returns LAN status        */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCLS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
/* Conditional compile to return no response */
/* Possibly reactivate a version of this command later */
#if 0
(void)p_cmd;
(void)p_resp_parm;
   /* function used for testing only */
   return NO_RESPONSE;
#else
   INT16    len;
   U_INT8   i;

   if( (p_cmd->parmv[0] == 1) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {
      len = 0;
      i = 0;
      while ((LAN_serial_number[i] != 0) && (i < 9))
      {
         *(p_resp_parm+len) = LAN_serial_number[i++];
         len++;
      }
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
      i = 0;
      while ((LAN_MAC_address[i] != 0) && (i < 17))
      {
         *(p_resp_parm+len) = LAN_MAC_address[i++];
         len++;
      }
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
      i = 0;
      while ((LAN_software_version[i] != 0) && (i < 15))
      {
         *(p_resp_parm+len) = LAN_software_version[i++];
         len++;
      }

      return len;
   }
   else
   {
      CmdErrorHandler( p_cmd, 1, SYNTAX_ERROR );
      return NO_RESPONSE;
   }
#endif
}

/***********************************************************************/
/* END FUNCTION: DoCCLS                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoCCIW                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCIW command which gives ID and time stamp   */
/*           information for the workfile.                             */
/* FORMAT:                                                             */
/*     manufacturer,product no.,serial no.,firmware rev, time, date    */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCIW(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT16  len;

   if( (p_cmd->parmv[0] == 1) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {
      len = 0;

      /* manufacturer */
      len += PutAsciiParam((BIT8 *)"HP",p_resp_parm);
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* product number */
      len += PutAsciiParam((BIT8 *)"6890",p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* product type */
      len += PutAsciiParam((BIT8 *)"GC",p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* Firmware rev */
      len += TransferVersion( p_resp_parm+len );
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* serial number */
      len += GetSerialNumber(p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* Time */
      (void)IntToDecFilled( GetFullClockTime(),p_resp_parm+len,6 );
      len += 6;
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* Date */
      (void)IntToDecFilled( GetFullDate(),p_resp_parm+len,6 );
      len += 6;

      return len;
   }
   else
   {
      return NO_RESPONSE;
   }

}

/***********************************************************************/
/* END FUNCTION: DoCCIW                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoCCDM                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCDM command which deletes stored methods    */
/*                                                                     */
/* FORMAT:                                                             */
/*     method number                                                   */
/*                                                                     */
/* RETURNED VALUE: OK, INVALID_PARAM                                   */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCDM(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32    entry;

   if ((p_cmd->parmv[0] == 1) &&
       (DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry) == OK) &&
       (entry > 0) && (entry <= 9)                                  )
   {
      if (MethodExists (entry) == OK)
      {
         DeleteMethod (entry);
      }
      return PutIntParam((U_INT16)OK, p_resp_parm, 0);
   }
   else
   {
      return PutIntParam((U_INT16)INVALID_PARAM, p_resp_parm, 0);
   }
}

/***********************************************************************/
/* END FUNCTION: DoCCDM                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCIM                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCIM command which loads a stored method     */
/*          into the Active Workfile.                                  */
/*                                                                     */
/* FORMAT:                                                             */
/*     method number                                                   */
/*                                                                     */
/* RETURNED VALUE: OK, INVALID_PARAM, NOT_INSTALLED,                   */
/*                 NOT_VALID_DURING_RUN, NOT_ALLOWED                   */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCIM(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32    entry;

   if( (p_cmd->parmv[0] == 1) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {
      Install_State = INSTALL_COMPLETE;
      return PutIntParam((INT32)Current_Method, p_resp_parm, 0);
   }

   if ((p_cmd->parmv[0] == 1) &&
       (DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry) == OK) &&
       (entry >= 0) && (entry <= 9)                                  )
   {
      if (RunInProgressOrPending())
      {
         Install_State = INSTALL_COMPLETE;
         return PutIntParam((U_INT16)NOT_VALID_DURING_RUN, p_resp_parm, 0);
      }

      return PutIntParam((U_INT16)DcLoadMethod(entry,p_cmd->comm_port), p_resp_parm, 0);

   }
   else
   {
      Install_State = INSTALL_COMPLETE;
      return PutIntParam((U_INT16)INVALID_PARAM, p_resp_parm, 0);
   }
}

/***********************************************************************/
/* END FUNCTION: DoCCIM                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCLM                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCLM command which returns a directory of    */
/*           the stored methods.                                       */
/* FORMAT:                                                             */
/*     <meth1_exists>,<meth1_name>,<meth1_time>,<meth1_date>,<meth2..  */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCLM(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT16  len;
   U_INT8 i;
   DATETIME datetime;

   (void) p_cmd;

   len = 0;

   for (i = 1; i <= 6; i++)
   {
      if (MethodExists(i) == OK)
      {
         len += PutAsciiParam((BIT8 *)"1",p_resp_parm+len);
      }
      else
      {
         len += PutAsciiParam((BIT8 *)"0",p_resp_parm+len);
      }

      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* Method name */
      len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+len);
      len += GetMethodName((BIT8 *)p_resp_parm+len, i);
      len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* Time */
      datetime = GetMethodDateTime (i);
      (void)IntToDecFilled( GetTime(&datetime),p_resp_parm+len,6 );
      len += 6;
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);

      /* Date */
      (void)IntToDecFilled( GetDate(&datetime),p_resp_parm+len,6 );
      len += 6;
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
   }

   return len-1;   /* drop last "," */
}

/***********************************************************************/
/* END FUNCTION: DoCCLM                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCNM                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCNM command which gets/sets the name of     */
/*           the active workfile.                                      */
/* FORMAT:                                                             */
/*     method name                                                     */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCNM(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT16  len;
   BIT8   clear;

   if( (p_cmd->parmv[0] == 1) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {
      len = 0;

      /* Method name */
      len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+len);
      len += GetMethodName((BIT8 *)p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+len);

      return len;
   }
   else
   {
      clear = TRUE;             /* Default: clear method dirty flag */

      if (p_cmd->parmv[0] > 1)
      {
         if ( (p_cmd->parmv[0] == 2) &&
              ((p_cmd->parms[p_cmd->parmv[2]] == '0') || (p_cmd->parms[p_cmd->parmv[2]] == '1') ) )
         {
            if (p_cmd->parms[p_cmd->parmv[2]] == '0')
            {
               clear = FALSE;  /* leave Method_Dirty unchanged */
            }
         }
         else
         {
            CmdErrorHandler( p_cmd, 2, SYNTAX_ERROR );
            return NO_RESPONSE;
         }
      }

      DCSetMethodName( (BIT8 *)&p_cmd->parms[p_cmd->parmv[1]], clear );

      return NO_RESPONSE;
   }

}

/***********************************************************************/
/* END FUNCTION: DoCCNM                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCSM                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCSM command which stores the active method  */
/*                                                                     */
/* FORMAT:                                                             */
/*     method number                                                   */
/*                                                                     */
/* RETURNED VALUE: OK, INVALID_PARAM, NOT_ALLOWED                      */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCSM(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32    entry;
   INT8     i;
   UI_ERR   error;

   if ((p_cmd->parmv[0] == 1) &&
       (DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry) == OK) &&
       (entry > 0) && (entry <= 6)                                  )
   {
      error = OK;

      for (i=1; i<=5; i++)
      {
         if ((entry != 6) && (i != entry) && (MethodExists(i) == OK) &&
             (StrNCmp(Active_Wkfile.name, Stored_Wkfile[i-1].name, 20)) )
         {
            error = NOT_ALLOWED; /* Duplicate names not allowed except service method */
         }
      }

      if (error == OK)
      {
/* REVISIT: handle out of memory error */
         (void)StoreMethod ((U_INT8) entry);
         if (entry != 6)
         {
            Current_Method = entry;
         }
         else
         {
            Current_Method = 0;   /* method 6 stored, but not in service mode */
         }

         UpdateMethodModified (p_cmd->comm_port);
      }

      return PutIntParam((INT32)error, p_resp_parm, 0);
   }
   else
   {
      return PutIntParam((U_INT16)INVALID_PARAM, p_resp_parm, 0);
   }
}

/***********************************************************************/
/* END FUNCTION: DoCCSM                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCER                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Read datacomm command set error log.                       */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoCCER(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{

INT16 length;
INT16 len;
INT16 index;
U_INT16 chan;

   chan = p_cmd->comm_port;
/* if (chan > DRTB_PORT) chan = 2; */

   length = 0;
   len = 0;


   for ( index = 0; index < Host_Error_Count[chan] ; index++)
   {
      StrNCpy( p_resp_parm, Host_Err_Log[chan][index].dsap,16);
      len = StrLen(p_resp_parm);
      length += len;
      p_resp_parm +=len;

      *p_resp_parm++ = ';';
      length++;
   }

   Copy2( "EN",p_resp_parm );
   length += 2;
   p_resp_parm +=2;


   Host_Error_Count[chan] = 0;

   return length;

}

/***********************************************************************/
/* END FUNCTION: DoCCER                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCRS                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Execute global reset.                                      */
/*     This command does a reboot of the system.  There are three      */
/*     options to commandr:                                            */
/*                  0 - minimal poweron tests                          */
/*                  1 - all poweron tests                              */
/*                  2 - memory reset and all poweron tests             */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCRS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   BIT8 boot;

   (void)p_resp_parm;

   boot = TRUE;

   /* if first param = 1 - skip poweron tests */
   switch(p_cmd->parmv[0])
   {
   case 0:
      /* tell IQ to skip the power on tests by default */
      Skip_Power_On_Test = TRUE;
      break;
   case 1:
      switch( p_cmd->parms[p_cmd->parmv[1]] )
      {
      case '0':
         /* skip some power on tests */
         Skip_Power_On_Test = TRUE;
         break;
      case '1':
         /* do all power on tests */
         Skip_Power_On_Test = FALSE;
         break;
      case '2':
         /* do memory rest and all power on tests */
         Skip_Power_On_Test = FALSE;
         PF_Start = 0;
         break;
      case '3':
         /* reset pf RAM and mfg RAM and reboot */
         Skip_Power_On_Test = FALSE;
         PF_Start = 0;
         MF_Start = 0;
         InvalidateMfgBackup();
         break;
      case '4':
         /* reset pf RAM and mfg RAM on next boot */
         Skip_Power_On_Test = FALSE;
         PF_Start = 0;
         MF_Start = 0;
         InvalidateMfgBackup();
         boot = FALSE;
         break;
      default:
         CmdErrorHandler(p_cmd,1, INVALID_PARAM);
         return NO_RESPONSE;
      }
      break;
   default:
      CmdErrorHandler(p_cmd,2, INVALID_PARAM);
      return NO_RESPONSE;
   }

   if (boot)
   {
      /* kill interrupts before restarting, interrupts will be enabled */
      /*  again as part of restarting */
      INTERRUPTS_OFF;
      /* jump to PowerUp which will reset system to poweron state */
/*-----------changed by wangwei---------------*/
//      __asm("   XREF boot:PowerUp");
//      __asm("   bra.L (PowerUp+8).L" ); /* Reboot */
printf("system is required to reboot!!!!\n");
/*-------------end change------------------------*/
      /* execution will never get to here */
   }

   return NO_RESPONSE;
}

/***********************************************************************/
/* END FUNCTION: DoCCRS                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCCR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCCR command, which starts an SCC run.       */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCCR(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{

CCOMP       ccomp;
UI_ERR      error;
U_INT16     length;

   (void)p_resp_parm;

   error = OK;
   switch (p_cmd->parms[0])
   {
   case '1':
      ccomp = CCOMP1;
      break;
   case '2':
      ccomp = CCOMP2;
      break;
   case '3':
      ccomp = CCOMP1_2;
      break;
   default:
      /* error - invalid parameter */
      error = INVALID_PARAM;
      CmdErrorHandler(p_cmd,1, error);
      return NO_RESPONSE;
   }

   error = StartBlankRun(ccomp, FALSE);
   length = PutIntParam((U_INT16)error, p_resp_parm, 0);
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoCCCR                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCCS                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCCS command, which reports the status of    */
/*          column compensation profiles 1 & 2.                        */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

static INT16 PutCCCSParams( pCCOMP_TABLE pccomp, BIT8 *p_resp_parm, INT16 len )
{
   len += PutIntParam((INT32)GetSccCollectState( pccomp ), p_resp_parm+len, 0 );
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);

   len += PutIntParam( (INT32)GetSccDataState( pccomp ), p_resp_parm+len, 0 );
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);

   len += IntToDecFilled( GetSccDataTime( pccomp ), p_resp_parm+len, 6 );
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);

   len += IntToDecFilled( GetSccDataDate( pccomp ), p_resp_parm+len, 6 );
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);

   len += PutIntParam((INT32)GetSccDataDetector( pccomp ), p_resp_parm+len, 0 );
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);

   len += PutIntParam((INT32)GetSccDetectorType( pccomp ), p_resp_parm+len, 0 );
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);

   return len;
}

static INT16 DoCCCS( BIT8 *p_resp_parm )
{
   U_INT16 len;

   len = PutCCCSParams( pCCOMP1, p_resp_parm, 0 );
   len = PutCCCSParams( pCCOMP2, p_resp_parm, len );

   len--;  /* Strip off the last comma */

   return len;
}

/***********************************************************************/
/* END FUNCTION: DoCCCS                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCCX                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCC1/2 command, which sets the detector type */
/*          for column compensation profile 1 or 2.                    */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCCX( CMD_TYPE *p_cmd, BIT8 *p_resp_parm, pCCOMP_TABLE pccomp )
{
   INT16     length;
   INT32       pos;
   UI_ERR      error;

   length = NO_RESPONSE;

   if ( p_cmd->parms[0] == '?' )
   {
      return PutIntParam( (INT32)GetSccSignalType( pccomp ), p_resp_parm, 0 );
   }
   else
   {
      if ( (error=DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &pos )) == OK )
      {
         error = SetSccSignalType( pccomp, (POSITION)pos );
      }

      if ( error != OK )
      {
         CmdErrorHandler( p_cmd, 1, error );
      }
   }

   return length;
}

/***********************************************************************/
/* END FUNCTION: DoCCCX                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCPM                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implements the CCPM command, which gives the host          */
/*          any change in the a parameter or configuration or          */
/*          powerfail since the last read.                             */
/*                                                                     */
/* RETURNED VALUE: error code is returned to host                      */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCPM(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{

U_INT16    length;
BIT8       tmp;
BIT8       tmp2;
U_INT16    chan;
PARAM_MOD_TYPE3 tmp3;

   chan = p_cmd->comm_port;

   INTERRUPTS_OFF;
       tmp = Parameter_Modified[chan].byte;
       Parameter_Modified[chan].byte = 0;
       tmp2 = Parameter_Modified2[chan].byte;
       Parameter_Modified2[chan].byte = 0;
   INTERRUPTS_ON;

   length = PutIntParam(tmp, p_resp_parm, 0);

   length += PutAsciiParam((BIT8 *)",", p_resp_parm+length);
   length += PutIntParam(tmp2, p_resp_parm+length, 0);

   tmp3.word = 0;

   if (Method_Dirty)
   {
      tmp3.bits.meth_dirty = 1;
   }

/*
   if (In_Service_Mode)
   {
      tmp3.bits.service_mode = 1;
   }
*/

/*
   if (GetKeyboardLock())
   {
      tmp3.bits.local_kbd = 1;
   }
*/

   if (GetLSMSeqLock())
   {
      tmp3.bits.meth_seq = 1;
   }

   if (GetClockTableSeqLock())
   {
      tmp3.bits.clk_tbl_exec = 1;
   }

   if (GetClockTableLock())
   {
      tmp3.bits.clk_tbl = 1;
   }

   if (GetRemoteStartLock())
   {
      tmp3.bits.rmt_start = 1;
   }

   if (GetStartRunLock())
   {
      tmp3.bits.start_key = 1;
   }

   if (GetDataCommKeyboardLock())
   {
      tmp3.bits.keyboard = 1;
   }

   if (GetSequenceLock())
   {
      tmp3.bits.sequence = 1;
   }

   if (DEVIATIONS_FOUND)
   {
      tmp3.bits.run_log = 1;
   }

   length += PutAsciiParam((BIT8 *)",", p_resp_parm+length);
   length += PutIntParam(tmp3.word, p_resp_parm+length, 0);
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoCCPM                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCMD                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the workfile command, which downloads and        */
/*              uploads a workfile (CCMD CCAD and CCBD.)               */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCMD(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
static U_INT16  WF_Entry;    /* next workfile entry */
BIT8    *resp_ptr;
U_INT16  len;
U_INT16  resp_len;
U_INT16 count;
WKFILE_CONTENTS wkfile_contents;
U_INT16 chan;

   chan = p_cmd->comm_port;
   if ( (chan == 4) || (chan == 5) )
   {
      chan -= 2;
   }

   /* initialize response length */
   resp_len = 0;

   if(p_cmd->parmv[0] == 1)
   {
      switch (p_cmd->opcode.int_op)
      {
      case  MAKEINT('M','D'):
         /* CCMD */
         wkfile_contents = GC_ONLY;
         break;
      case  MAKEINT('A','D'):
         /* CCAD */
         wkfile_contents = ALS_ONLY;
         break;
      default:
         /* CCBD */
         wkfile_contents = BOTH;
         break;
      }

     switch (p_cmd->parms[0])
      {

      /* WORKFILE DOWNLOAD */
      case 'B':
      case 'C':
      case 'E':
         /* workfile was downloaded send response back */
         (void) PutAsciiParam((BIT8 *)&(p_cmd->parms[0]), p_resp_parm);

         /* should only return one character (B,C,E) */
         return 1;

      /* WORKFILE UPLOAD */
      case '?':

         resp_ptr = p_resp_parm;
         resp_len = 0;
         WF_Entry = 0;

         /* build a workfile in Upld_wkfile.buffer */
         BuildWkFile(Upld_wkfile[chan].buffer,Upld_wkfile[chan].hex_crc,wkfile_contents,chan);

         *resp_ptr++ = 'B';
         resp_len++;
         /* seperate each command with a ';' */
         *resp_ptr++ = ';';
         resp_len++;

         /* start workfile with '"' */
         *resp_ptr++ = '"';
         resp_len++;

         /* add entries to output msg until full or no more to send */
         while( (WF_Entry < Upld_wkfile[chan].total_entries) &&
                   (resp_len + UpldWFEntrySize(WF_Entry, chan) < MAX_WF_TX_SIZE) )
         {
            len = UpldWFEntrySize(WF_Entry, chan);
            StrNCpy(resp_ptr,Upld_wkfile[chan].p_entry[WF_Entry],len);
            resp_ptr += len;
            resp_len += len;
            WF_Entry++;
         }


         /* end workfile with '"' */
         *resp_ptr++ = '"';
         resp_len++;

         break;

      case '+':
         /* send next part of workfile */

         if(WF_Entry < Upld_wkfile[chan].total_entries)
         {
            /* more entries to send, so send them */
            resp_ptr = p_resp_parm;
            resp_len = 0;

            *resp_ptr++ = 'C';
            resp_len++;
            /* seperate each command with a ';' */
            *resp_ptr++ = ';';
            resp_len++;

            /* start workfile with '"' */
            *resp_ptr++ = '"';
            resp_len++;

            while( (WF_Entry < Upld_wkfile[chan].total_entries) &&
                    (resp_len + UpldWFEntrySize(WF_Entry, chan) < MAX_WF_TX_SIZE) )
            {
               len = UpldWFEntrySize(WF_Entry, chan);
               StrNCpy(resp_ptr,Upld_wkfile[chan].p_entry[WF_Entry],len);
               resp_ptr += len;
               resp_len += len;
               WF_Entry++;
            }


            /* end workfile with '"' */
            *resp_ptr++ = '"';
            resp_len++;

         }
         else if(WF_Entry==Upld_wkfile[chan].total_entries) /* first WF_Entry is 0 */
         {
            /* end of workfile; send to send crc */
            WF_Entry++;
            resp_ptr = p_resp_parm;
            resp_len = 0;

            *resp_ptr++ = 'E';
            resp_len++;
            /* seperate each command with a ';' */
            *resp_ptr++ = ';';
            resp_len++;

            /* start workfile with '"' */
            *resp_ptr++ = '"';
            resp_len++;


            /* add 4 byte crc to message and increment length by 4 */
            for(count = 0; count <4; count++)
            {
               *resp_ptr++ = *(Upld_wkfile[chan].hex_crc+count);
            }
            resp_len += 4;


            /* end workfile with '"' */
            *resp_ptr++ = '"';
            resp_len++;
         }
         else    /* WF_Entry > Upld_wkfile[chan].total_entries */
         {
            /* no more to send */
            WF_Entry++;
            resp_ptr = p_resp_parm;
            resp_len = 0;

            *resp_ptr++ = 'E';
            resp_len++;

         }

         break;

      default:
         /* error - no a valid parameter */
         CmdErrorHandler(p_cmd, 1, INVALID_PARAM);
         return NO_RESPONSE;
      }
      return   resp_len;
   }
   else
   {
         /* error - not a valid number of parameter */
         CmdErrorHandler(p_cmd, 1, NUM_OF_PARAM);
         return NO_RESPONSE;
   }
}
/***********************************************************************/
/* END FUNCTION: DoCCMD                                                */
/***********************************************************************/




/***********************************************************************/
/* FUNCTION: DoCCMC                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the workfile check command, which checks the     */
/*               last workfile downloaded (CCMC,CCAC,CCBD.)            */
/*         Response is error code for OK or PARAM_CHANGED.             */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCMC(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
WKFILE_CONTENTS wkfile_contents;
U_INT16 chan;


      chan = p_cmd->comm_port;
      if ( (chan == 4) || (chan == 5) )
      {
         chan -= 2;
      }

      switch (p_cmd->opcode.int_op)
      {
      case  MAKEINT('M','C'):
         /* CCMD */
         wkfile_contents = GC_ONLY;
         break;
      case  MAKEINT('A','C'):
         /* CCAD */
         wkfile_contents = ALS_ONLY;
         break;
      default:
         /* CCBC */
         wkfile_contents = BOTH;
         break;
      }

   return  PutIntParam((U_INT16)CheckWorkfile(Dwnld_wkfile[chan].buffer,
              Dwnld_wkfile[chan].length, Dwnld_wkfile[chan].hex_crc, wkfile_contents, chan),
                p_resp_parm, 0);
}
/***********************************************************************/
/* END FUNCTION: DoCCMC                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCMW                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the workfile check command, which checks the     */
/*               last workfile downloaded (CCMC,CCAC,CCBD.)            */
/*         Response is error code for OK or PARAM_CHANGED.             */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCMW( BIT8 *p_resp_parm)
{
U_INT16  len;
INT16    word;
INT32    warning;
BIT8    *p_end_parm;

   len = 0;
   word = 1;

   warning = GetMethodWarning(word);
   p_end_parm = (BIT8 *)FormatHexadecimal((U_INT32)warning,
                                          (BIT8 *)p_resp_parm, 0);
   len = (p_end_parm - p_resp_parm);

   for( word  = 2; word <= METHOD_WARNING_WORD_COUNT; word++ )
   {
      len += PutAsciiParam((BIT8 *)",",p_resp_parm+len);
      warning = GetMethodWarning(word);
      p_end_parm = (BIT8 *)FormatHexadecimal((U_INT32)warning,
                                             (BIT8 *)p_resp_parm+len, 0);
      len = len + (p_end_parm - (p_resp_parm+len));
   }

   return len;

}
/***********************************************************************/
/* END FUNCTION: DoCCMW                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCMI                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the workfile install command (CCMI,CCAI,CCBI.)   */
/*          Response will be code for OK or NOT_ALLOWED.               */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCMI(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
WKFILE_CONTENTS wkfile_contents;
INT16 length;
U_INT16 chan;

   chan = p_cmd->comm_port;
   if ( (chan == 4) || (chan == 5) )
   {
      chan -= 2;
   }

   switch (p_cmd->opcode.int_op)
   {
   case  MAKEINT('M','I'):
      /* CCMD */
      wkfile_contents = GC_ONLY;
      break;
   case  MAKEINT('A','I'):
      /* CCAD */
      wkfile_contents = ALS_ONLY;
      break;
   default:
      /* CCBI */
      wkfile_contents = BOTH;
      break;
   }


   if ( RunInProgressOrPending() )
   {
      /* in a run so do not install */
      length = PutIntParam((U_INT16)NOT_ALLOWED,p_resp_parm,0);
   }
   else
   {
      InstallWorkfile(Dwnld_wkfile[chan].buffer, Dwnld_wkfile[chan].length,Dwnld_wkfile[chan].hex_crc,wkfile_contents,chan);
      /* return OK */
      length = PutIntParam((U_INT16)OK,p_resp_parm,0);

   }
   return length;
}
/***********************************************************************/
/* END FUNCTION: DoCCMI                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoCCSL                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCSL command, which uploads and downloads an */
/*          IQ sequence.                                               */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCSL(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
INT32 len;
UI_ERR error;

  if ( (p_cmd->parmv[0] > 0) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
  {
      len = GetSequenceParameters (p_resp_parm);
      return len;
  }
  else
  {
      error =  SetSequenceParameters (p_cmd);
      len = PutIntParam((U_INT16)error,p_resp_parm,0);
      return len;
  }

}
/***********************************************************************/
/* END FUNCTION: DoCCSL                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCSC                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCSC command, which checks the last sequence */
/*            downloaded.                                              */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCSC(BIT8 *p_resp_parm)
{
INT32 len;
UI_ERR error;

      error =  CheckSequenceCheckArea();
      len = PutIntParam((U_INT16)error,p_resp_parm,0);
      return len;

}
/***********************************************************************/
/* END FUNCTION: DoCCSC                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCSI                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCSI command, which installs the last        */
/*             sequence downloaded.                                    */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCSI(BIT8 *p_resp_parm)
{
INT32 len;
UI_ERR error;

      error =  InstallSequenceParameters();
      len = PutIntParam((U_INT16)error,p_resp_parm,0);
      return len;

}
/***********************************************************************/
/* END FUNCTION: DoCCSI                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCSX                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCSX command, which is used to control a     */
/*          sequence and to check on it's status.                      */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/


INT16 DoCCSX(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 len;
   INT32 sample;
   UI_ERR error;

   if ( (p_cmd->parmv[0] > 0) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {
      len = PutIntParam((INT32) GetSequenceState(), p_resp_parm, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      len += PutIntParam((INT32) Seq_Substate, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      len += PutIntParam(0, p_resp_parm+len, 0);  /* Start Mode, 0 always in 6890N */
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      len += PutIntParam((INT32) GetAlsTowerMode(FRONT), p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetCurrentFrontSample();
      if (!SequenceInProgress()) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetFrontSample();
      if (sample < 0) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetCurrentFrInjNum();
      if (!SequenceInProgress()) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetCurrentRepeatNum();
      if (!SequenceInProgress()) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      len += PutIntParam((INT32)Last_Inj_Abort, p_resp_parm+len, 0);

      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetCurrentSubseq();
      if (!SequenceInProgress()) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      len += PutIntParam((INT32) GetAlsTowerMode(BACK), p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetCurrentBackSample();
      if (!SequenceInProgress()) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetBackSample();
      if (sample < 0) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      sample = GetCurrentBkInjNum();
      if (!SequenceInProgress()) sample = 0;
      len += PutIntParam(sample, p_resp_parm+len, 0);
   }
   else  /* Sequence control */
   {
      if (p_cmd->parmv[0] > 0)
      {
         error = OK;

         if ( StrNCmp(&p_cmd->parms[p_cmd->parmv[1]], (BIT8 *)"START", 5) )
         {
            error = StartSequence();
         }
         else
         {
            if ( StrNCmp(&p_cmd->parms[p_cmd->parmv[1]], (BIT8 *)"STOP", 4) )
            {
               StopSequence();   /* no errors */
            }
            else
            {
               if ( StrNCmp(&p_cmd->parms[p_cmd->parmv[1]], (BIT8 *)"PAUSE", 5) )
               {
                  PauseSequence();  /* no errors */
               }
               else
               {
                  if ( StrNCmp(&p_cmd->parms[p_cmd->parmv[1]], (BIT8 *)"RESUME", 6) )
                  {
                     error = ResumeSequence();
                  }
                  else
                  {
                     if ( StrNCmp(&p_cmd->parms[p_cmd->parmv[1]], (BIT8 *)"PUSH", 4) )
                     {
                        PushSequence();    /* no errors */
                     }
                     else
                     {
                        error = SYNTAX_ERROR;
                     }
                  }
               }
            }
         }
      }
      else
      {
         error = MISSING_PARAM;
      }

      len = PutIntParam((U_INT16)error, p_resp_parm, 0);
   }

   return len;
}

/***********************************************************************/
/* END FUNCTION: DoCCSX                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoCCAF                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCAF command, which uploads formatted        */
/*             sampler setpoints.                                      */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCAF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
INT16 chars, len;
U_INT16 chan;

   chan = p_cmd->comm_port;

   /* test for valid number of parameter */
   if (p_cmd->parmv[0] != 1)
   {
      CmdErrorHandler(p_cmd, 1, NUM_OF_PARAM);
      return NO_RESPONSE;
   }

   switch (p_cmd->parms[p_cmd->parmv[1]])
   {
   case '?':    /* request for first line */
      /* rewind formatted listing */
      RewindSamplerFmt(chan);

      /* insert beginning prefix */
      len = PutAsciiParam((BIT8 *)"B;", p_resp_parm);
      break;

   case '+':    /* request for continuation line */
      /* insert continuation prefix */
      len = PutAsciiParam((BIT8 *)"C;", p_resp_parm);
      break;

   default:     /* invalid request */
      CmdErrorHandler(p_cmd, 1, INVALID_PARAM);
      return NO_RESPONSE;
   }

   /* read a formatted line */
   chars = ReadSamplerFmt(p_resp_parm+len,chan);

   /* did we get EOF? */
   if (chars < 0)
   {
      /* overwrite prefix with EOF */
      len = PutAsciiParam((BIT8 *)"E", p_resp_parm);
   }
   else
   {
      /* increment string length -- a blank listing line will add 0 */
      len += chars;
   }

   return len;
}
/***********************************************************************/
/* END FUNCTION: DoCCAF                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCMF                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCMF command, which uploads formatted        */
/*             method setpoints.                                       */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCMF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
INT16 chars, len;
U_INT16 chan;

   chan = p_cmd->comm_port;

   /* test for valid number of parameter */
   if (p_cmd->parmv[0] != 1)
   {
      CmdErrorHandler(p_cmd, 1, NUM_OF_PARAM);
      return NO_RESPONSE;
   }

   switch (p_cmd->parms[p_cmd->parmv[1]])
   {
   case '?':    /* request for first line */
      /* rewind formatted listing */
      RewindMethodFmt(chan);

      /* insert beginning prefix */
      len = PutAsciiParam((BIT8 *)"B;", p_resp_parm);
      break;

   case '+':    /* request for continuation line */
      /* insert continuation prefix */
      len = PutAsciiParam((BIT8 *)"C;", p_resp_parm);
      break;

   default:     /* invalid request */
      CmdErrorHandler(p_cmd, 1, INVALID_PARAM);
      return NO_RESPONSE;
   }

   /* read a formatted line */
   chars = ReadMethodFmt(p_resp_parm+len,chan);

   /* did we get EOF? */
   if (chars < 0)
   {
      /* overwrite prefix with EOF */
      len = PutAsciiParam((BIT8 *)"E", p_resp_parm);
   }
   else
   {
      /* increment string length -- a blank listing line will add 0 */
      len += chars;
   }

   return len;
}
/***********************************************************************/
/* END FUNCTION: DoCCMF                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoCCSF                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCSF command, which uploads formatted        */
/*             sequence setpoints.                                     */
/*                                                                     */
/* RETURNED VALUE: length of error code                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCSF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
INT16 chars, len;

   /* test for valid number of parameter */
   if (p_cmd->parmv[0] != 1)
   {
      CmdErrorHandler(p_cmd, 1, NUM_OF_PARAM);
      return NO_RESPONSE;
   }

   switch (p_cmd->parms[p_cmd->parmv[1]])
   {
   case '?':    /* request for first line */
      /* rewind formatted listing */
      RewindSeqFmt();

      /* insert beginning prefix */
      len = PutAsciiParam((BIT8 *)"B;", p_resp_parm);
      break;

   case '+':    /* request for continuation line */
      /* insert continuation prefix */
      len = PutAsciiParam((BIT8 *)"C;", p_resp_parm);
      break;

   default:     /* invalid request */
      CmdErrorHandler(p_cmd, 1, INVALID_PARAM);
      return NO_RESPONSE;
   }

   /* read a formatted line */
   chars = ReadSeqFmt(p_resp_parm+len);

   /* did we get EOF? */
   if (chars < 0)
   {
      /* overwrite prefix with EOF */
      len = PutAsciiParam((BIT8 *)"E", p_resp_parm);
   }
   else
   {
      /* increment string length -- a blank listing line will add 0 */
      len += chars;
   }

   return len;
}
/***********************************************************************/
/* END FUNCTION: DoCCSF                                                */
/***********************************************************************/
/***********************************************************************/
/* FUNCTION: DoCCMX                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCMX command, which sets the active workfile */
/*             to default setpoint values.                             */
/*                                                                     */
/* RETURNED VALUE: length of error response                            */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCMX(BIT8 *p_resp_parm)
{
INT16 length;
UI_ERR error;
   error = SetDefaultMethod();
   length = PutIntParam((U_INT16)error, p_resp_parm, 0);
   return length;
}
/***********************************************************************/
/* END FUNCTION: DoCCMX                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCCE                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCCE command. This command is only used as   */
/*      a place holder for method loading.  It will be inserted        */
/*      the configuration and the method setpoints of the workfile to  */
/*      indicate end of configuration.                                 */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/
INT16 DoCCCE(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   /* if '?' return 0 (used to give response to build workfile) */
   if((p_cmd->parms[p_cmd->parmv[1]]) == '?')
   {
      return  PutAsciiParam((BIT8 *)"0", p_resp_parm);
   }
   else
   {
      return NO_RESPONSE;
   }
}
/***********************************************************************/
/* END FUNCTION: DoCCCE                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCPO                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCPO command. This command is used to setup  */
/*      the pass through communication path for communicating with     */
/*      the sampler.                                                   */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCPO(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
INT32  entry;
UI_ERR error;


   if (p_cmd->parmv[0] == 0)
   {
      return  PutIntParam((U_INT16)MISSING_PARAM, p_resp_parm, 0);
   }

   error = DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry);

   /* check for valid parameters */
   if( ((U_INT16)error != 0 ) || (entry < 0 ) || (entry >= NUM_PATHS) )
   {
      return  PutIntParam((U_INT16)INVALID_PARAM, p_resp_parm, 0);
   }

   /* make sure path is not already set up */
   if(Com_Path[(U_INT16)entry].hdsap.char_hdsap[0]!=0)
   {
      return  PutIntParam((U_INT16)NOT_ALLOWED, p_resp_parm, 0);
   }

   /* if entry already in table,  reject command */
   if(PathTableEntry(&p_cmd->ssap.char_ssap[0]) != -1)
   {
      return  PutIntParam((U_INT16)NOT_ALLOWED, p_resp_parm, 0);
   }

   Com_Path[(U_INT16)entry].hdsap.char_hdsap[0] = p_cmd->ssap.char_ssap[0];
   Com_Path[(U_INT16)entry].hdsap.char_hdsap[1] = p_cmd->ssap.char_ssap[1];
   Com_Path[(U_INT16)entry].host_port = p_cmd->comm_port;

   return  PutIntParam((U_INT16)OK, p_resp_parm, 0);
}

/***********************************************************************/
/* END FUNCTION: DoCCPO                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoCCPC                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCPC command. This command is used to        */
/*      remove pass through communication paths from the instrument.   */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCPC(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
INT32  entry;
UI_ERR error;


   if (p_cmd->parmv[0] == 0)
   {
      return  PutIntParam((U_INT16)MISSING_PARAM, p_resp_parm, 0);
   }

   error = DecToInt(&p_cmd->parms[p_cmd->parmv[1]],0,&entry);

   /* check for valid parameters */
   if( ((U_INT16)error != 0 ) || (entry < 0 ) || (entry >= NUM_PATHS) )
   {
      return  PutIntParam((U_INT16)INVALID_PARAM, p_resp_parm, 0);
   }

   Com_Path[(U_INT16)entry].hdsap.char_hdsap[0] = 0;
   Com_Path[(U_INT16)entry].hdsap.char_hdsap[1] = 0;
   Com_Path[(U_INT16)entry].host_port = 0;

   return  PutIntParam((U_INT16)OK, p_resp_parm, 0);
}
/***********************************************************************/
/* END FUNCTION: DoCCPC                                                */
/***********************************************************************/
/***********************************************************************/
/* FUNCTION: DoCCPL                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Implement the CCPL command. This command lists all pass    */
/*      through communication paths in the instrument.                 */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoCCPL( BIT8 *p_resp_parm)
{
INT16 len;
U_INT16 index;

   len = 0;
   for( index = 0; index < (NUM_PATHS-1) ; index++ )
   {
      if(Com_Path[index].hdsap.int_hdsap != 0)
      {
         Copy2(Com_Path[index].hdsap.char_hdsap, p_resp_parm+len );
         len +=2;
      }
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
      if(Com_Path[index].hdsap.int_hdsap != 0)
      {
         len += PutIntParam(Com_Path[index].host_port, p_resp_parm+len, 0);
      }
      len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
   }
   if(Com_Path[index].hdsap.int_hdsap != 0)
   {
      Copy2(Com_Path[index].hdsap.char_hdsap, p_resp_parm+len );
      len +=2;
   }
   len += PutAsciiParam((BIT8 *)",", p_resp_parm+len);
   if(Com_Path[index].hdsap.int_hdsap != 0)
   {
      len += PutIntParam(Com_Path[index].host_port, p_resp_parm+len, 0);
   }

   return  len;
}
/***********************************************************************/
/* END FUNCTION: DoCCPL                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: CCOpcodes                                                 */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls routines needed to implement the CC commands.        */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 CCOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len)
{
INT16           parm_len;

   (void) max_resp_len;

   parm_len = NO_RESPONSE;
   switch (p_cmd->opcode.int_op)
   {
      case  MAKEINT('I','D'):
        parm_len = DoCCID(p_resp_parm);
        break;
      case  MAKEINT('I','W'):
        parm_len = DoCCIW(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('E','R'):
        parm_len = DoCCER(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('R','S'):
        parm_len = DoCCRS(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('C','R'):
        parm_len = DoCCCR(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('C','S'):
        parm_len = DoCCCS(p_resp_parm);
        break;
      case  MAKEINT('C','1'):
        parm_len = DoCCCX(p_cmd, p_resp_parm, pCCOMP1 );
        break;
      case  MAKEINT('C','2'):
        parm_len = DoCCCX(p_cmd, p_resp_parm, pCCOMP2 );
        break;
      case  MAKEINT('A','D'):
      case  MAKEINT('B','D'):
      case  MAKEINT('M','D'):
        parm_len = DoCCMD(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('P','M'):
        parm_len = DoCCPM(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('A','C'):
      case  MAKEINT('B','C'):
      case  MAKEINT('M','C'):
        parm_len = DoCCMC(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('A','W'):
      case  MAKEINT('B','W'):
      case  MAKEINT('M','W'):
        parm_len = DoCCMW(p_resp_parm);
        break;
      case  MAKEINT('A','I'):
      case  MAKEINT('B','I'):
      case  MAKEINT('M','I'):
        parm_len = DoCCMI(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('D','M'):                  /* EOS: Delete stored method */
        parm_len = DoCCDM(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('I','M'):                  /* EOS: Install stored method */
        parm_len = DoCCIM(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('L','M'):                  /* EOS: Directory list stored methods */
        parm_len = DoCCLM(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('N','M'):                  /* EOS: Name active method */
        parm_len = DoCCNM(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('S','M'):                  /* EOS: Store active method */
        parm_len = DoCCSM(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('L','A'):                  /* Set/Read Lan Addresses */
        parm_len = DoCCLA(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('L','S'):                  /* Read Lan status */
        parm_len = DoCCLS(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('S','L'):
        parm_len = DoCCSL(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('S','C'):
        parm_len = DoCCSC(p_resp_parm);
        break;
      case  MAKEINT('S','I'):
        parm_len = DoCCSI(p_resp_parm);
        break;
      case  MAKEINT('S','X'):
        parm_len = DoCCSX(p_cmd, p_resp_parm);
        break;
      case  MAKEINT('A','F'):
        parm_len = DoCCAF(p_cmd, p_resp_parm);
        break;
      case  MAKEINT('M','F'):
        parm_len = DoCCMF(p_cmd, p_resp_parm);
        break;
      case  MAKEINT('S','F'):
        parm_len = DoCCSF(p_cmd, p_resp_parm);
        break;
      case  MAKEINT('M','X'):
        parm_len = DoCCMX(p_resp_parm);
        break;
      case  MAKEINT('C','E'):
        parm_len = DoCCCE(p_cmd, p_resp_parm);
        break;

      case  MAKEINT('E','O'):
        parm_len = DoCCEO(p_cmd,p_resp_parm);
        break;

      case  MAKEINT('P','O'):
        parm_len = DoCCPO(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('P','C'):
        parm_len = DoCCPC(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('P','L'):
        parm_len = DoCCPL(p_resp_parm);
        break;
      case  MAKEINT('C','H'):
        parm_len = DoCmd(p_cmd, p_resp_parm, &mCCCH);
        break;
      case  MAKEINT('9','8'):
        parm_len = DoCC98(p_cmd,p_resp_parm);
        break;
      case  MAKEINT('9','9'):
        parm_len = DoCC99(p_cmd,p_resp_parm);
        break;
      default:
         parm_len = NO_RESPONSE;
         CmdErrorHandler(p_cmd,0,INVALID_OP);
         break;
   }
   return parm_len;
}


/***********************************************************************/
/* END FUNCTION: CCOpcodes                                             */
/***********************************************************************/





/***********************************************************************/
/* FUNCTION: CC_Cmds                                                   */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls function which executes a command if one is          */
/*          available on the command queue.                            */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

void CC_Cmds(void)
{
   ExecCmds(&CC_Cmd_Q,CCOpcodes);
}

/***********************************************************************/
/* END FUNCTION: CC_Cmds                                               */
/***********************************************************************/


